package pers.duorhs.app.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pers.duorhs.common.socket.service.AppSocketService;

/**
 * @author Duorhs
 * @date 2022/5/9 8:43
 */
@RestController
@RequestMapping("app")
@Tag(name = "APP")
@AllArgsConstructor
@Slf4j
public class AppController {
    private final AppSocketService socketService;

    @Operation(summary = "客户排队")
    @PostMapping("lineup")
    public String lineUp(@RequestParam String customer) {
        socketService.login(customer);
        return "OK:" + customer + "开始排队";
    }

    @Operation(summary = "推送Socket消息", description = "给客户所关联的CSR(前端)SocketClient推送消息")
    @PostMapping("push")
    public String push(@RequestParam String customer, @RequestParam String msg) {
        socketService.push(customer, msg);
        return "OK:" + customer + "给CSR端推送消息";
    }

    @Operation(summary = "结束业务办理", description = "")
    @PostMapping("end")
    public String end(@RequestParam String customer) {
        socketService.end(customer);
        return "OK:" + customer + "结束业务";
    }
}
